class Solution {
public:
    int findMin(vector<int>& nums) {
        int left = 0;
        int right = nums.size()-1;
        if(left < right && nums[left] < nums[right]) return nums[left];
        while(left < right)
        {
            while(left < right && nums[left]==nums[left+1]) left++;
            while(left < right && nums[right-1]==nums[right]) right--;
            if(left==right) return nums[left];
            int mid = (left+right) / 2;
            if(nums[mid] >= nums[right])
                left = mid+1;
            else
                right = mid;
        }

        return nums[left];
    }
};